import com.bottomlord.rest.client.DefaultClientBuilder;
import org.junit.Test;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ChenYue
 * @date 2021/3/31 18:41
 */
public class RestClientDemo {
    @Test
   public void testGet() {
       Client client = DefaultClientBuilder.newClient();
       Response response = client
               .target("http://127.0.0.1:8080/hello")
               .request()
               .method(HttpMethod.GET);

       String content = response.readEntity(String.class);

       System.out.println(content);
   }

   @Test
   public void testPost() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", 1);
        map.put("name", "chenyue");
       Client client = DefaultClientBuilder.newClient();
       Response response = client
               .target("http://127.0.0.1:8080/hello")
               .request()
               .method(HttpMethod.POST, Entity.json(map));

       String content = response.readEntity(String.class);

       response.close();
       client.close();

       System.out.println(content);
   }
}
